package com.eastidea.live.servlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class ExceptionHandler implements HandlerExceptionResolver {

	private Log log = LogFactory.getLog(getClass());

	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {

		log.warn("Handle exception: " + ex.getClass().getName());
		ex.printStackTrace();
		String url = request.getRequestURL().toString();

//		// mobile webpage error
//		if (url.indexOf("/mobi") > 0 || url.indexOf("/a/") > 0) {
//			return new ModelAndView("redirect:/nav/mobiError");
//		}
//
//		// frontend site error
//		if (url.indexOf("/front") > 0) {
//			return new ModelAndView("redirect:/nav/frontError");
//		}
//
//		// admin site error
//		if (url.indexOf("/back") > 0) {
//			return new ModelAndView("redirect:/nav/backError");
//		}
//
//		return new ModelAndView("redirect:/nav/frontError");
		return null;
	}

}
